home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / Jooky / jookyclient.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-01  |  1.4 KB  |  79 lines

  1. #include "includes.h"
  2. #include "defines.h"
  3. #include "funcs.h"
  4.  
  5. void jookyclient(host,cmd)
  6.     char *host;
  7.     char *cmd;
  8. {
  9.     char *buf;
  10.     char *greeting;
  11.     int sockfd ;
  12.     struct hostent *he ;
  13.     struct sockaddr_in their_addr ;
  14.  
  15.     buf=calloc(1,2048);
  16.     greeting=calloc(1,2048);
  17.  
  18.     if ((he=gethostbyname(host)) == NULL)
  19.     {
  20.         perror("gethostbyname");
  21.         exit(1);
  22.     }
  23.  
  24.     if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
  25.     {
  26.         perror("socket");
  27.         exit(1);
  28.     }
  29.  
  30.     their_addr.sin_family = AF_INET;
  31.     their_addr.sin_port = htons(port);
  32.     their_addr.sin_addr = *((struct in_addr *)he->h_addr);
  33.     bzero(&(their_addr.sin_zero),8);
  34.  
  35.     if (connect(sockfd,(struct sockaddr *)&their_addr,\
  36.         sizeof(struct sockaddr)) == -1)
  37.     {
  38.         perror("connect");
  39.         exit(1);
  40.     }
  41.  
  42.     read(sockfd,greeting,80);
  43.     if ((strncmp(greeting,"welcome!",8)==0) && (usepasswd==1))
  44.     {
  45.         printf("no password required.\n");
  46.         shutdown(sockfd,2);
  47.         free(buf);
  48.         exit(0);
  49.     }
  50.     
  51.     if ((strncmp(greeting,"password:",9)==0) && (usepasswd==0))
  52.     {
  53.         printf("password required!\n");
  54.         shutdown(sockfd,2);
  55.         free(buf);
  56.         exit(0);
  57.     }
  58.  
  59.     if ((strncmp(greeting,"password:",9)==0) && (usepasswd==1))
  60.     {
  61.         usleep(100000);
  62.         write(sockfd,password,strlen(password));
  63.     }
  64.  
  65.     usleep(100000);
  66.     write(sockfd,cmd,strlen(cmd));
  67.     usleep(100000);
  68.  
  69.     if (strncmp(cmd,"quer",4)==0)
  70.     {
  71.         read(sockfd,buf,2048);
  72.         printf ("%s\n",buf);
  73.     }
  74.     
  75.     shutdown(sockfd,2);
  76.     free(buf);
  77.     exit(0);
  78. }
  79.